//
//  ZXSTechnologyViewController.m
//  demo
//
//  Created by maxine on 2016/11/13.
//  Copyright © 2016年 maxine. All rights reserved.
//

#import "ZXSTechnologyViewController.h"
#import "ZXSTechnologyTableViewCell.h"
#import "ZXSTechnologyCollectionViewCell.h"
#import "ZXWeiKaiTongAlertView.h"

@interface ZXSTechnologyViewController ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDataSource,UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *rightCollectView;
@property (weak, nonatomic) IBOutlet UITableView *leftTableView;


@end

@implementation ZXSTechnologyViewController
static NSString * const reuseIdentifier = @"collectionCell";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"学农技";
    self.leftTableView.delegate = self;
    self.leftTableView.dataSource = self;
    self.leftTableView.separatorColor = [UIColor whiteColor];
    
    self.rightCollectView.delegate = self;
    self.rightCollectView.backgroundColor =[UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    self.rightCollectView.scrollEnabled = NO;
    self.rightCollectView.bounces = NO;
    //间距
    
    //每行个数
    //宽
    CGFloat width =(SCREEN_WIDTH-108)/3;
    NSLog(@"%f",self.rightCollectView.bounds.size.width);
    //高
    CGFloat height = width;
    CGFloat margin = 0;
    layout.minimumLineSpacing = margin;
    layout.minimumInteritemSpacing = margin;
    layout.itemSize = CGSizeMake(width, height);
    self.rightCollectView.dataSource = self;
    self.rightCollectView.backgroundColor = [UIColor whiteColor];
    self.rightCollectView.collectionViewLayout = layout;
    //创建一个xib对象
    UINib *nib = [UINib nibWithNibName:@"ZXSTechnologyCollectionViewCell" bundle:nil];
    //注册机制
    [self.rightCollectView registerNib:nib forCellWithReuseIdentifier:reuseIdentifier];
    //代码可扩展性,使item得尺寸根据xib的尺寸设置变化
    //实例化cell
    //    ZXSTechnologyCollectionViewCell *cell = [[nib instantiateWithOwner:nil options:nil] lastObject];
    
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ZXSTechnologyTableViewCell *cell = [ZXSTechnologyTableViewCell cellWithTableView:tableView];
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    view.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
    cell.selectedBackgroundView = view;
    switch (indexPath.row) {
        case 0:
            cell.titleText.text = @"作物";
            break;
        case 1:
            cell.titleText.text = @"服务";
            break;
            
        case 2:
            cell.titleText.text = @"资讯";
            break;
            
        default:
            break;
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ZXWeiKaiTongAlertView *alert = [[ZXWeiKaiTongAlertView alloc]init];
    alert.center = self.view.center;
    [self.view addSubview:alert];
    
    
    
    
}


- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 9;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    ZXSTechnologyCollectionViewCell *cell = [ZXSTechnologyCollectionViewCell cellWithCollectionView:collectionView forIndexPath:indexPath];
    cell.imageView.image = [UIImage imageNamed:@"04-zhangshan"];
    cell.title.text = @"大豆";
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    ZXWeiKaiTongAlertView *alert = [[ZXWeiKaiTongAlertView alloc]init];
    alert.center = self.view.center;
    [self.view addSubview:alert];
    
    
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
